#include <iostream>
#include <string>

using namespace std;

int f( int n)
{for (int i=2;i<n;i++)
if (n%i==0) return 0;
    return 1;
}

int main()
{string s,s1,s2;
int ch=0;
int p=100;
int m,a,b,c,a1,a2;

string cif[10]{"zero", "one", "two", "three", "four", "five", "six","seven", "eight", "nine"};

getline(cin,s);
s=s+' ';

    while (s.length()!=0)

    {   m=s.find(' ');
        s1=s.substr(0,m);
        for (int i=0;i<=10;i++)
            if (cif[i]==s1)  a=i;
        s=s.substr(m+1);
        ch+=a*p;
        p=p/10;

        }

for (int i=ch-1;i>0;i--)
if (f(i)==1){a1=i;break;}
for (int i=ch+1;i<1050;i++)
if (f(i)==1){a2=i;break;}

if ((ch-a1)<=(a2-ch))
    cout<<a1<<endl;
else cout<<a2;
    return 0;
}
